package com.violet.controller.manager;

import com.violet.domain.dto.manager.MCategoryDto;
import com.violet.domain.result.Result;
import com.violet.domain.vo.manager.MCategoryVo;
import com.violet.service.manager.MCategoryService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/manager/category")
@RequiredArgsConstructor
public class MCategoryController {

    private final MCategoryService service;

    @GetMapping
    public Result<List<MCategoryVo>> getAll() {
        return Result.success(service.getAll(), "获取所有数据");
    }

    @PostMapping
    public Result<MCategoryVo> create(@ModelAttribute MCategoryDto dto) {
        return Result.success(service.create(dto), "创建数据");
    }

    @DeleteMapping("/{id}")
    public Result<Boolean> deleteById(@PathVariable String id) {
        return Result.success(service.deleteById(id), "删除数据");
    }

    @PutMapping("/{id}")
    public Result<MCategoryVo> updateById(@PathVariable String id, @ModelAttribute MCategoryDto dto) {
        return Result.success(service.updateById(id, dto), "更新数据");
    }

}
